#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int res=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){res=(res<<1)+(res<<3)+(c^48);c=getchar();}
	return res*f;
}
void write(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
int n;
int ans;
int a[114514],tmp[114514];
map<int,int>mp;
int Pow[114514];
const int mod=998244353,p=131;
void dfs(int h)
{
	if(!mp.count(h)) ++ans;
	else return;
	mp[h]=1;
	for(int i=1;i<n;i++) 
		if(a[i]!=a[i+1]) 
		{
			int tmp1=a[i],tmp2=a[i+1];
			a[i]=max(a[i],a[i+1]),a[i+1]=max(a[i+1],a[i]);
			dfs((h+(a[i]-tmp1+mod)%mod*Pow[i]+(a[i+1]-tmp2+mod)%mod*Pow[i+1])%mod);
			a[i]=tmp1,a[i+1]=tmp2;
		}
}
signed main()
{
	freopen("after.in","r",stdin);
	freopen("after.out","w",stdout);
	n=read();
	Pow[0]=1;
	for(int i=1;i<=n;i++) Pow[i]=Pow[i-1]*p%mod;
	int h=0;
	for(int i=1;i<=n;i++) a[i]=read(),h=(h+Pow[i]*a[i])%mod;
	dfs(h);
	write(ans);
	return 0;
}
